<template>
  <div>
    <p>当前区块号: {{ blockNumberNow }}</p>
    <el-button @click="getBlockNumber">获取区块号</el-button>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data () {
    return {
      blockNumberNow: ''
    };
  },
  methods: {
    async getBlockNumber () {
      try {
        const response = await axios.post('https://hiwcq.com/api', {
          jsonrpc: '2.0',
          method: 'eth_blockNumber',
          params: [],
          id: 1
        }, {
          headers: {
            'Content-Type': 'application/json'
          }
        });
        console.log(response.data);
        if (response.data && response.data.result) {
          this.blockNumberNow = parseInt(response.data.result, 16);
        }
      } catch (error) {
        console.error('Error fetching block number:', error);
      }
    }
  }
};
</script>

<style scoped>
/* Add any styles you need for your component */
</style>
